/* DIRECTORIES
 * Hierarchical string-named spaces of objects of some kind.
 * Directories manage secure access to their namespace.  They are the root of several kinds
 * of security constrained objects.
 *
 * Wherever permissions are granted, directory objects are created which include the
 * permissions.  When directories that do not have any permission explicitly set are
 * requested by the application, they are created on demand and default permissions
 * are determined by the parent.
 * This simple scheme has the potential to perform badly if we walk over a large
 * namespace.  It is also tricky to adapt it to installing new permission maps on the fly.
 * On the other hand, it works quite nicely for recording every name the application
 * visits, so perhaps you could do a "Do you want to accept this cookie?" type interactive
 * permission system.
 */

typedef struct _KewDirectoryObject KewDirectoryObject;

#define UNKNOWN 0
#define ALLOWED 1
#define DENIED 2
#define INHERITED 3

struct _KewDirectoryObject {
    KewObject super;
    KewDirectoryObject *parent;
    guint read_permission;
    guint write_permission;
    GHashTable *children;
};

KewDirectoryObject *kew_directory_new(void) 
{
    KewDirectoryObject dir = kew_object_new(KewDirectoryObject, 0);
    dir->parent = NULL;
    dir->children = g_hash_table_new(g_str_hash, g_str_equal);
    return dir;
}

void kew_directory_add(KewDirectoryObject *parent, char *name, KewObject *object)
{
    KewDirectoryObject *child = kew_directory_new();
    child->parent = parent;
    g_hash_table_insert(parent->children, (gpointer) name, (gpointer) object);
}


/*
 * Files
 */

#include <glib.h>

typedef struct _KewFileDirectoryObject KewFileDirectoryObject;

struct _KewFileDirectoryObject {
    KewObject super;
    KewFileDirectoryObject *parent;
    char *name;
    /* if the name really exists or has simply been requested without checking? */
    /* the underlying resource handle? */
};


KewFileDirectoryObject *kew_file_directory_wrap(char *path)
{
    KewFileDirectoryObject *dir = kew_object_new(KewFileDirectoryObject, 0);
    dir->path = path;
}

KewFileDirectoryObject *kew_file_directory_new(char *path)
{
    return kew_file_directory_wrap(g_strdup(path));
}

KEW_METHOD(kew_file_directory_root)
{
    results[0] = kew_file_directory_new("");
}

KEW_METHOD(kew_file_directory_home)
{
    results[0] = kew_file_directory_new(g_get_home_dir());
}

KEW_METHOD(kew_file_directory_temporary)
{
    results[0] = kew_file_directory_new(g_get_temp_dir());
}

KEW_METHOD(kew_file_directory_current)
{
    results[0] = kew_file_directory_wrap(g_get_current_dir());
}

KEW_METHOD(kew_file_directory_children)
{
    GDir *dir
}
